import {getJourneyInfo, getJourneyStrategy} from "@/api/flowModel";


export function useGetFlowModel() {
  const lazyLoadModelSelect = async (node: any, resolve: (arg0: any) => void) => {
    if (node.level === 0) {
      const result = await getMarketingJourneyInfoList()
      resolve(result)
    } else { // level === 1 只有两级
      const result = await getMarketingJourneyStrategyEntityList({id: node.value})
      resolve(result)
    }
  }

  const getMarketingJourneyInfoList = async () => {
    const rs = await getJourneyStrategy({
      currentPage: 1,
      showCount: -1
    });

    return rs.payload?.map((item) => {
      return {
        value: item.id,
        label: item.name,
      }
    }) ?? [];
  }

  const getMarketingJourneyStrategyEntityList = async ({id}: { id: number }) => {
    const rs = await getJourneyInfo({
      currentPage: 1,
      showCount: -1,
      id: id,
    })

    return rs.payload?.map((item) => {
      return {
        value: item.id,
        label: item.name,
        leaf: true,
      }
    }) ?? [];
  }

  return {
    lazyLoadModelSelect
  }
}
